<?php
namespace app\dsadmin\model;
use think\Model;
use think\Db;

class PayModel extends Model
{
    protected $name = 'pay';

    public function getPayByWhere($map, $Nowpage, $limits)
    {
        return $this->alias('e')->field('e.*,m.account,m.nickname')->where($map)->join("member m", "e.userid = m.id",'LEFT')->page($Nowpage, $limits)->order('e.id desc')->select();
    }
    
    public function getPayByWhere1($map, $Nowpage, $limits)
    {
        return $this->alias('e')->field('e.*,m.account,m.nickname')->where($map)->join("member m", "e.userid = m.id",'LEFT')->page($Nowpage, $limits)->order('e.end_time desc')->select();
    }

    public function getAllCount($map)
    {
        return $this->where($map)->count();
    }

    public function dakuan($id)
    {
        try
        {
            $this->where(['id' => ['in', $id]])->update(['zt' => "已支付",'end_time' => date("Y-m-d H:i:s")]);
            return ['code' => 1, 'data' => '', 'msg' => '确认成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    
    public function beizhu($id,$text)
    {
        try
        {
            $this->where(['id' => ['in', $id]])->update(['imgurl' => $text,'end_time' => date("Y-m-d H:i:s")]);
            return ['code' => 1, 'data' => '', 'msg' => '备注成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
    
    public function bohui($id){
        try
        {
            $this->where(['id' => ['in', $id]])->update(['zt' => "驳回打款",'end_time' => date("Y-m-d H:i:s")]);
            return ['code' => 1, 'data' => '', 'msg' => '确认成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
}
